package com.happy_hao.msg.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.happy_hao.msg.exception.ServiceException;
import com.happy_hao.msg.mapper.SenderMapper;
import com.happy_hao.msg.po.Sender;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class SenderUtil {

    @Resource
    private SenderMapper senderMapper;

    public Sender getSender(Object identifier){
        Sender sender;
        QueryWrapper<Sender> queryWrapper = new QueryWrapper<>();
        if(identifier == null){
            throw new ServiceException("您传入的标识符为空");
        }else if(identifier instanceof String) {
            sender = senderMapper.selectOne(queryWrapper.eq("username", identifier));
        }else if (identifier instanceof Long) {
            sender = senderMapper.selectOne(queryWrapper.eq("sender_id", identifier));
        }else {
            throw new ServiceException("您传入的标识符不合法");
        }
        return sender;
    }

}
